package com.fmsz.xmly.adapters.anchor;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.fmsz.xmly.R;
import com.fmsz.xmly.entitys.anchor.AnchorEntity;

import java.util.List;

public class AnchorAdapter extends RecyclerView.Adapter<AnchorAdapter.ViewHolder> {
    private List<AnchorEntity> list;
    private Context context;

    public AnchorAdapter(List<AnchorEntity> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_anchor, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.title.setText(list.get(position).getTitle());
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
        AnchorContentAdapter adapter = new AnchorContentAdapter(list.get(position).getList(), context);
        holder.recyclerView.setAdapter(adapter);
        adapter.notifyDataSetChanged();


    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView title;
        private RecyclerView recyclerView;

        public ViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.anchor_tv);
            recyclerView = (RecyclerView) itemView.findViewById(R.id.anchor_recycler);
        }
    }
}
